package kr.couponplay.android.support;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.content.Context;

public class DisplayUtils {
	private static final float DEFAULT_HDIP_DENSITY_SCALE = 1.5f;

	public static int dPFromPixel(Context context, int pixel) {
		float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pixel / DEFAULT_HDIP_DENSITY_SCALE * scale);
	}

	public static int pixelFromDp(Context context, int dp) {
		float den = context.getResources().getDisplayMetrics().density;
		return (int) (dp * den+0.5);
	}
	
	public static int widthPixels(Context context) {
		return context.getResources().getDisplayMetrics().widthPixels;
	}
	
	public static String numFormat(int num) {
		DecimalFormat df = new DecimalFormat("#,##0");
		return df.format(num);
	}
	
	public static String dateFormat(long now) {
		return dateFormat(new Date(now));
	}
	
	public static String dateFormat(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.KOREA);
		return format.format(date);
	}
	
	public static String dateFormat(Date date, String dateFormat) {
		SimpleDateFormat format = new SimpleDateFormat(dateFormat, Locale.KOREA);
		return format.format(date);
	}
}
